const path = require('path');

const htmlWebpackPlugin = require('html-webpack-plugin');
const copyWebpackPlugin = require('copy-webpack-plugin');
const extractTextWebpackPlugin = require("extract-text-webpack-plugin");

var config = {
    entry: {
        index: './src/index.js',
        album2: './src/album2.js',
        album3: './src/album3.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    },
    plugins: [
        new htmlWebpackPlugin({
            filename: 'index.html',
            chunks: ['index'],
            title: '3D Album',
            inject: true,
            template: './src/templates/index.ejs'
        }),
        new htmlWebpackPlugin({
            filename: 'album2.html',
            chunks: ['album2'],
            title: 'Album2',
            inject: true,
            template: './src/templates/album2.ejs'
        }),
        new htmlWebpackPlugin({
            filename: 'album3.html',
            chunks: ['album3'],
            title: 'Album3',
            inject: true,
            template: './src/templates/album3.ejs'
        }),
        new extractTextWebpackPlugin({
            filename: (getPath) => {
                return getPath('css/[name].css');
            },
            allChunks: true
        }),
        new copyWebpackPlugin([{
            from: __dirname + '/src/static',
            to: './static'
        }])
    ],
    module: {
        rules: [{
            test: /\.css$/,
            use: extractTextWebpackPlugin.extract({
                fallback: 'style-loader',
                use: [
                    "css-loader"
                ]
            })
        }, {
            test: /\.ejs$/,
            use: ['ejs-loader']
        }]
    }
};

module.exports = function (env) {
    env = env || 'dev';
    return require("./webpack." + env + ".config.js")(env, config);
}